package model.inventory;

import java.util.HashMap;
import java.util.Map;

import model.contents.ContentType;

public class ContentTypeMapper {
	private Map<Integer, ContentType> map;
	private Map<Integer, String> containerMap;

	public ContentTypeMapper() {
		map = new HashMap<Integer, ContentType>();
		containerMap = new HashMap<Integer, String>();
	}

	public void put(String fieldName, ContentType type, Integer containerId) {
		map.put(containerId, type);
		containerMap.put(containerId, fieldName);
	}
	
	public ContentType get(int containerId) {
		if(map.containsKey(containerId)) {
			return map.get(containerId);
		} else {
			// return a non-playable content type instead of null
			return ContentType.OTHER;
		}
	}
	
	
	public void removeMapping(int containerId) {
		this.map.remove(containerId);
		containerMap.remove(containerId);
	}
	
	public String[] getFieldNames() {
		return this.map.values().toArray(new String[]{});
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for(Integer key: this.map.keySet()) {
			sb.append("container: " + key + ", type: " + map.get(key) + ", field: " + containerMap.get(key)).append("\n");
		}
		return sb.toString();
	}
	
	public Integer[] getContainerIds() {
		Integer[] arr = new Integer[this.containerMap.size()];
		int index =0;
		for(Integer containerID : this.containerMap.keySet()) {
			arr[index] = containerID;
			index++;
		}
		return arr;
	}

	public String getFieldName(Integer containerID) {
		return this.containerMap.get(containerID);
	}
}
